/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.HashMap;
import java.util.*;
import java.util.Vector;
import java.util.Arrays;


public class Vector_class implements Comparable{

    public static int accnum_count;
    public static int max_segs;
    int document_id = 0;
    
    // Added to Check the trial of NB CVS

    Vector_class() {
    }

    public Vector_class(int x, int y) {
        accnum_count = x;
        max_segs = y;
    }
    
    public final HashMap<Integer,Float> seg_relevance = new HashMap<Integer, Float>(5,0.95f);
    Set set = seg_relevance.keySet();
    Iterator itermap = set.iterator();
    
    float relevance_score = 0f;
    Vector<Integer> seg_number = new Vector<Integer>();
    //Vector<Float> relevance = new Vector<Float>();

    public void Initialize_Vector_size(Vector_class[] v1, int doc_length) {
        max_segs = doc_length;
        accnum_count = v1.length;
        //relevance_score = new float[accnum_count];

        for (int i = 0; i < v1.length; i++) {
            v1[i].seg_number.ensureCapacity(max_segs);
            //v1[i].relevance.ensureCapacity(max_segs);
        }
    }

    public void Process_Vectors(Vector_class[] v) {

        //float[][] f1 = new float[1][max_segs];

        System.out.println("The relevance Score for the documents are ");
        System.out.println(" Document ID        Relevance Score");

        for (int i = 0; i < v.length; i++) {

            // Object[] array1 = new Object[max_segs];
            // v[i].seg_number.copyInto(array1);

            int iter = v[i].seg_number.size();
            System.out.println(" ITER : " + iter);

            for (int j = 0; j < iter; j++) {
                //f1[0][j] = v[i].seg_relevance.relevance.elementAt(j);
                if(v[i].seg_relevance.containsKey(j))
            	v[i].relevance_score = (v[i].seg_relevance.get(j) * Phase2.weighted_vectors[j]) + v[i].relevance_score;
            }
            System.out.println(" Relevance Score for Document " + v[i].document_id + " is : " + v[i].relevance_score);

        }
        
        Sort_and_Display(v);
        
    }
    
    public void Sort_and_Display(Vector_class[] v){
        Arrays.sort(v);
        
        System.out.println("Document ID      Relevance Score");
        for(int i = 0; i < v.length; i++)
        {
            System.out.println(v[i].document_id +"        "+v[i].relevance_score);
        }
        
    }

    public int compareTo(Object obj) {
        
        Vector_class temp = (Vector_class)obj;
        if(this.relevance_score<temp.relevance_score){
           return -1; 
        }
        else if(this.relevance_score > temp.relevance_score)
        {
            return 1;
        }

    return 0;
    }
    
    public float Vector_Product(Vector_class v) {
        		
    	float result = 0f;
    	
    	for (int i : this.seg_relevance.keySet()) {
    		if(Phase2.weights.containsKey(i)&& this.seg_relevance.containsKey(i))
            result = (Phase2.weights.get(i) * this.seg_relevance.get(i)) + result;
        }
        return(result);
    }
   

 }


